package leetcode.周赛.第275场;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/1/9 14:49
 * @description：https://leetcode-cn.com/problems/earliest-possible-day-of-full-bloom/
 */
public class 全部开花的最早一天 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.earliestFullBloom(new int[]{1, 4, 3}, new int[]{2, 3, 1}));
    }

    class Solution {
        public int earliestFullBloom(int[] plantTime, int[] growTime) {
            int n = plantTime.length;
            int[][] nums = new int[n][2];
            for (int i = 0; i < n; i++) {
                nums[i][0] = plantTime[i];
                nums[i][1] = growTime[i];
            }
            Arrays.sort(nums, (a, b) -> b[1] - a[1]);
            int end = 0;
            int cur = 0;
            for (int[] num : nums) {
                cur += num[0];
                int curEnd = cur + num[1];
                if (curEnd > end) end = curEnd;
            }
            return end;
        }
    }
}
